



//网络请求封装
import Request_post from "../../../../../request/Request_post"
import Request_get from "../../../../../request/Request_get"

//系统设置项目:(请求地址-在封装中已经引入，这里不需要;   api调用的Appid-partner_app_id;   渠道ID-as_appid)
import config from '../../../../../config/config'; 

//引入时间函数
var dateArray = require("../../../../../utils/CustomFunction/getDayFirstNowLast.js")
var time = require("../../../../../utils/CustomFunction/getNowTime.js")

//引入日期时间：（格式化、反格式化）函数
var formatDate = require("../../../../../utils/CustomFunction/dateFormat.js")
var unformatDate = require("../../../../../utils/CustomFunction/dateUnFormat.js")

Page({

	/**
	 * 页面的初始数据
	 */
	data: {

		//Title图片的网络地址链接（第一套：可换固定背景）
		Title_Image:config.imageUrl+"title_member_CompSugg_Record.jpg",

		calendar:config.imageUrl+"calendar.png",

		//待回复-角标
		WaitReply:config.imageUrl+"WaitReply.png",
		//已回复-角标
		AlreadyReply:config.imageUrl+"AlreadyReply.png",
		//已完结-角标
		AlreadyOver:config.imageUrl+"AlreadyOver.png",
		//已作废-角标
		AlreadyInvalidate:config.imageUrl+"AlreadyInvalidate.png",

		//空页面
		EmptyPage:config.imageUrl+"EmptyPage.png",

		Tabs_list:[
      {name:"全部",isActive:true},
			{name:"待处理",isActive:false},
			{name:"处理中",isActive:false},
			{name:"已完结",isActive:false},
			{name:"已作废",isActive:false}
		],

		index:0,

	},

	

	//Title图片网络外联地址加载失败，则使用本地地址
	bindImgError:function(e){
    this.setData({
      Title_Image: "../../../../../image/title_member_CompSugg_Record.png"
    })
	},
	
	handleItemChang(e){  // （01-待回复、02-已回复、03-已处理完毕、09-作废）
		var that = this
		const index = e.detail.index;
		const Tabs_list = that.data.Tabs_list;
		//方式一：使用forEach 遍历数组，遍历数组的时候，修改了v，也会导致源数组被修改
		Tabs_list.forEach((v,i)=>i===index? v.isActive=true:v.isActive=false);
		that.setData({
			Tabs_list:Tabs_list,
			index:index
		})
		if(index == 0){   //全部：s_stsid: "all"
			// Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "all"
      },
      function(res){
				// console.log(res)
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(index == 1){   //待处理：s_stsid: "01"
			// Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "01"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
		}else if(index == 2){	//已回复：s_stsid: "02"
			// Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "02"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
		}else if(index == 3 ){	//处理完毕：s_stsid: "03"
			// Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "03"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
		}else if(index == 4 ){	//处理完毕：s_stsid: "09"
			// Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
			{
				bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "09"
			},
			function(res){
				if(res){
					that.setData({CompSugg_list:res.return_data})
				}
			})
		}
	},



	// 点击开始日期事件
	bindbdateChange: function(e) {
    var that = this
		that.setData({
      bdate:unformatDate.DatString(e.detail.value)
		})
    //修改开始时间后，4种状态的数据按修改后的时间（开始时间）重新获取
    if(that.data.index == 0){
      var that = this
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "all"
      },
      function(res){
				// console.log(res)
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 1){
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "01"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 2){
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "02"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 3){
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "03"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 4){
			// Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "09"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
		}
    


	 },
	 


	 // 点击截至日期事件
	bindedateChange: function(e) {
    var that = this
		that.setData({
      edate:unformatDate.DatString(e.detail.value)
		})
    //修改开始时间后，4种状态的数据按修改后的时间（开始时间）重新获取
    if(that.data.index == 0){
      var that = this
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "all"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 1){
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "01"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 2){
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "02"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 3){
      // Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "03"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
    }else if(that.data.index == 4){
			// Api请求:13-003 会员咨询投诉列表查询
      Request_get.get(
			config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
      {
        bdtm: that.data.bdate+"000000",
				edtm: that.data.edate+"235959",
				stsid: "09"
      },
      function(res){
        if(res){
					that.setData({CompSugg_list:res.return_data})
        }
      })
		}
    


   },











	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {

		//获取本月第一天 & 最后一天日期
    var that=this
    const getdateArray = dateArray.getDayFirstNowLast()
    this.setData({
      bdate:getdateArray[0],
      edate:getdateArray[2]
		})


		// Api请求:13-003 会员咨询投诉列表查询
    getApp().loginPromise.then(v => {	//app.js的Promise成功回调（全局变量赋值成功后才执行请求）
			Request_get.get(
				config.domainName+'api_wxmkt_server/mbrcpl/listmbrcpl',
				{
					bdtm: that.data.bdate+"000000",
					edtm: that.data.edate+"235959",
					stsid: "all"
				},
				function(res){
					if(res){
						that.setData({CompSugg_list:res.return_data})
						// console.log(that.data.CompSugg_list)
					}
				}
			)
		})

		


	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})